package org.tcs.com.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
import org.hibernate.envers.RelationTargetAuditMode;
import org.joda.time.LocalDateTime;

@Entity
@Audited
@Table(name = "INCIDENTS")
public class Incident {

	@NotAudited
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="INCIDENT_ID")
	private  long id;

	@NotAudited
	@Column(name="REFERENSE_ID")
	private String referenseID;

	@NotAudited
	@Column(name = "START_DATE")
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
	private  LocalDateTime issueStartDate;

	@NotAudited
	@Column(name = "RESOLVED_DATE")
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
	private LocalDateTime resolvedDate;
	
	@NotAudited
	@ManyToOne
	@JoinColumn(name = "RAISED_BY",nullable=false,updatable=false,insertable=false)
	private User raisedBy;
	
	@NotAudited
	@OneToMany(mappedBy="incident",cascade = {CascadeType.ALL})
	private List<Comment> comments;

	@NotAudited
	@OneToMany(mappedBy="incident",cascade = {CascadeType.ALL})
	private List<Attachment> attachments;


	public List<Attachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<Attachment> attachments) {
		this.attachments = attachments;
	}

	public User getRaisedBy() {
		return raisedBy;
	}

	public void setRaisedBy(User raisedBy) {
		this.raisedBy = raisedBy;
	}

	
	public List<Comment> getComments() {
		return comments;
	}
	
	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}
	
	@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
	@ManyToOne
	@JoinColumn(name = "ASSIGNED_USER",updatable=false,insertable=false)
	private User assignedTo;
	
	public User getAssignedTo() {
		return assignedTo;
	}
	
	public void setAssignedTo(User assignedTo) {
		this.assignedTo = assignedTo;
	}
	
	@NotAudited
	@ManyToOne
	@JoinColumn(name = "ASSIGNED_GROUP",nullable=false,updatable=false,insertable=false)
	private Group assignedGroup;

	public Group getAssignedGroup() {
		return assignedGroup;
	}

	public void setAssignedGroup(Group assignedGroup) {
		this.assignedGroup = assignedGroup;
	}

	@Audited
	@Enumerated(EnumType.STRING)
	@Column(name="STATUS")
	private Status status;

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

    @NotAudited
	@Column(name="SEVERITY")
	@Enumerated(EnumType.STRING)
	private Severity severity;
	
	public Severity getSeverity() {
		return severity;
	}
	
	public void setSeverity(Severity severity) {
		this.severity = severity;
	}

	@NotAudited
	@ManyToOne
	@JoinColumn(name="PROJECT",nullable=false,updatable=false,insertable=false)
	private Project project;

	@NotAudited
	@ManyToOne
	@JoinColumn(name="COMPONENT",nullable=false,updatable=false,insertable=false)
	private Component projectComponent;

	/*private List<Attachment> attachments;*/

	

	public Project getProject() {
		return project;
	}

	public void setProject(Project type) {
		this.project = type;
	}

	public Component getProjectComponent() {
		return projectComponent;
	}

	public void setProjectComponent(Component projectComponent) {
		this.projectComponent = projectComponent;
	}

	/**
	 * @param issueStartDate
	 */
	public Incident(LocalDateTime issueStartDate, long id) {
		this.issueStartDate = issueStartDate;
		this.id = id;
	}

	/**
	 * 
	 */
	public Incident() {
	}

	public String getReferenseID() {
		return referenseID;
	}

	public void setReferenseID(String referenceID) {
		this.referenseID = referenceID;
	}

	

	public long getId() {
		return id;
	}

	

	public LocalDateTime getResolvedDate() {
		return resolvedDate;
	}

	public void setResolvedDate(LocalDateTime resolvedDate) {
		this.resolvedDate = resolvedDate;
	}


	@SuppressWarnings("unused")
	private void setId(long id) {
		this.id = id;
	}

	public void setIssueStartDate(LocalDateTime issueStartDate) {
		this.issueStartDate = issueStartDate;
	}

	public LocalDateTime getIssueStartDate() {
		return issueStartDate;
	}



}